from symbol import return_stmt

import FindXY
import FindFace
import GetScreen
import GetTxt
import random
import cv2
import pyautogui
import pyperclip

if __name__ == '__main__':
    cv2.waitKey(3000)

    while True:

        cv2.waitKey(1000)

        # 获取截图
        tempScreenName = "temp/screen" + str(random.randint(1, 1000000)) + ".png"
        GetScreen.capture_screen_and_save(tempScreenName)
        img = cv2.imread(tempScreenName)

        # cv2.waitKey(random.randint(1000, 3000))

        while True:

            # 查找是否有点赞
            top_left, bottom_right, center, max_val = FindXY.find_template_in_image("img/followOhter.png",
                                                                                    tempScreenName)
            print(f"点关注位置：{center}")

            if max_val > 0.8:
                print("已点赞")
                cv2.rectangle(img, top_left, bottom_right, (0, 0, 255), 20)

                # 保存更新
                cv2.imwrite(tempScreenName, img)

                # 移动光标并点击
                pyautogui.moveTo(center[0], center[1], duration=0.4)  # duration 是移动所需时间(秒)
                cv2.waitKey(random.randint(500, 600))
                pyautogui.click(center[0], center[1])
                cv2.waitKey(random.randint(500, 600))
                pyautogui.moveTo(10, 10, duration=0.4)  # duration 是移动所需时间(秒)
                cv2.waitKey(random.randint(500, 600))

                #再次截图
                tempScreenName1 = "temp/screen" + str(random.randint(1, 1000000)) + ".png"
                GetScreen.capture_screen_and_save(tempScreenName1)
                img1 = cv2.imread(tempScreenName1)

                # 查找是否有需要确认取消关注
                top_left1, bottom_right1, center1, max_val1 = FindXY.find_template_in_image("img/notFollow.png",
                                                                                        tempScreenName1)

                if max_val1 > 0.8:
                    pyautogui.moveTo(center1[0], center1[1], duration=0.4)  # duration 是移动所需时间(秒)
                    cv2.waitKey(random.randint(1000, 3000))
                    pyautogui.click(center1[0], center1[1])
            else:
                break

        pyautogui.moveTo(150, 400, duration=0.4)  # duration 是移动所需时间(秒)
        print("开始自动滚动")
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)
        cv2.waitKey(random.randint(500, 600))
        pyautogui.scroll(-200)